#include <stdio.h>
#include <stdarg.h>

// 打印时指定宽度和填充字符
void padf (size_t sz, int padch, char *fmt, ...) {
    int wid;
    va_list va;

    // Get the width that will be output.

    va_start (va, fmt);
    wid = vsnprintf (NULL, 0, fmt, va);
    va_end (va);

    // Pad if it's shorter than desired.

    while (wid++ <= sz)
        putchar (padch);

    // Then output the actual thing.

    va_start (va, fmt);
    vprintf (fmt, va);
    va_end (va);
}

int main (void) {
    padf (18, '#', "%.2f\n", 123.0);
    padf (8, '*', "%.2f\n", 3.0);
    return 0;
}